package ace.module.oauth2.server.core.autoconfig;

import ace.cmp.jetcache.anno.config.EnableAceMethodCache;
import ace.cmp.security.autoconfig.SecurityBootstrapAutoConfigure;
import ace.cmp.spring.data.jdbc.querydsl.core.QuerydslJdbcRepositoryExtendFactoryBean;
import ace.module.oauth2.server.core.autoconfig.config.Oauth2ServerRestAuthenticationConfig;
import ace.module.oauth2.server.core.autoconfig.config.Oauth2ServerSecurityConfig;
import ace.module.oauth2.server.core.impl.Oauth2ServerCoreBootstrapScanner;
import ace.module.oauth2.server.core.impl.dao.repository.RepositoryScanner;
import ace.module.oauth2.server.core.impl.properties.Oauth2ServerCoreProperties;
import ace.module.oauth2.server.core.impl.properties.Oauth2ServerSecurityProperties;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;

/**
 * boostrap auto config.
 *
 * @author Caspar
 */
@AutoConfigureAfter({SecurityBootstrapAutoConfigure.class})
@EnableJdbcRepositories(
    basePackageClasses = {RepositoryScanner.class},
    repositoryFactoryBeanClass = QuerydslJdbcRepositoryExtendFactoryBean.class)
@EnableConfigurationProperties({
  Oauth2ServerSecurityProperties.class,
  Oauth2ServerCoreProperties.class
})
@EnableAceMethodCache(basePackageClasses = {Oauth2ServerCoreBootstrapScanner.class})
@ComponentScan(
    basePackageClasses = {
      Oauth2ServerCoreBootstrapScanner.class,
      Oauth2ServerRestAuthenticationConfig.class,
      Oauth2ServerSecurityConfig.class
    })
@Configuration
public class Oauth2ServerCoreAutoConfig {
    @Bean
    public GroupedOpenApi oauth2ServerGroupedOpenApi() {
        return GroupedOpenApi.builder()
            .group("oauth2Server")
            .displayName("oauth2服务")
            .packagesToScan(Oauth2ServerCoreBootstrapScanner.class.getPackageName())
            .build();
    }
}
